﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace WpfAnimation
{
    /// <summary>
    /// PageAnimationClock.xaml 的交互逻辑
    /// </summary>
    public partial class PageAnimationClock : Page
    {
        ScaleTransform myScaleTransform;
        public PageAnimationClock()
        {
            InitializeComponent();

            myScaleTransform = new ScaleTransform(1, 1);
            myButton.RenderTransform = myScaleTransform;

          
        }

        private void myButton_Click(object sender, RoutedEventArgs e)
        {
            DoubleAnimation myAnimation =
                new DoubleAnimation(
                    1, // "From" value

                    5, // "To" value 

                    new Duration(TimeSpan.FromSeconds(5))
                );
            myAnimation.AutoReverse = true;

            // Create a clock the for the animation.

            AnimationClock myClock = myAnimation.CreateClock();

            //1.据说这样写效率比较高
            myScaleTransform.ApplyAnimationClock(
                ScaleTransform.ScaleXProperty, myClock);
            myScaleTransform.ApplyAnimationClock(
                ScaleTransform.ScaleYProperty, myClock);

            //myScaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, myAnimation);
            //myScaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, myAnimation);
        }
    }
}
